package com.example.aboutwork.nonblocking;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import static com.example.aboutwork.nonblocking.FutureFunc.unit;
import static com.example.aboutwork.nonblocking.FutureFunc1.lazyUnit;

public class TestNoBlocking {


    public static void main(String[] args) throws InterruptedException {

        ExecutorService es = Executors.newFixedThreadPool(10);
        String result = new Nonblocking<>(Lists.newArrayList(1, 2, 3, 4, 5, 7, 8))
                .map(String::valueOf)
                .flatMap(str -> unit(str + "xxxxx"))
                .run(es);
        System.err.println(result);
        List<FutureFunc1<Integer>> futures = Lists.newArrayList();
        for (int i = 0; i < 100; i++) {
            int finalI = i;
            futures.add(lazyUnit(()-> finalI));
        }
        System.err.println(FutureFunc1.sequence(futures).run(es));


    }
}
